/**
 * 添加服务接口
 */

//引入Q模块
let Q = require('q');
//引入公共函数
let util = require('../../util');

let index = function(getData, postData, config, _redis, db) {
	let deferred = Q.defer();
	if(postData.funSid && postData.funName) {
		let funId;
		util.createRandomStr(6).then(function(_funId) {
			funId = _funId;
			return db.insert('storeFunInfo', {
				funSid: postData.funSid,
				funId: funId,
				funName: postData.funName
			});
		}, function() {
			//生成服务ID失败
			deferred.reject('-0203');
		}).then(function() {
			deferred.resolve({
				funId: funId
			});
		}, function() {
			//添加服务失败
			deferred.reject('-0204');
		});
	}
	else {
		//添加服务接口参数不足
		deferred.reject('-0202');
	}
	return deferred.promise;
}

module.exports = {
	index: index
}